﻿<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/template1.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>报名</title>
<!-- InstanceEndEditable -->
<script type="text/javascript" src="../js/common.js"></script>
<script type="text/javascript" src="../js/qmsk-1.2.js"></script>
<link href="../css/Pager.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/jquery.pager.js"></script>
<script type="text/javascript" src="../js/gbRst.js"></script>
<script type="text/javascript" src="../js/utils.js"></script>
<script type="text/javascript" src="../js/checkLogin.js"></script>
<link href="../css/style.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="../js/shopSelecterNew.js"></script>
<script type="text/javascript" src="../js/pagination.js"></script>
<script type="text/javascript" src="shadowbox/shadowbox.js"></script>
<link href="shadowbox/shadowbox.css" rel="stylesheet" />
<link rel="stylesheet" href="../css/default.css" />
<script type="text/javascript" src="../js/doubleDate2.0.js"></script>
<!-- InstanceBeginEditable name="head" -->
<!-- InstanceEndEditable -->
<style type="text/css">
#window_change p label span img {
	border: 1px solid #CCCCCC;
	height: 90px;
	vertical-align: middle;
	width: 70px;
}
</style>
<script type="text/javascript">
	$(function() {
		 _htmlUploadUrl="apply";
		 _indexUrl="indexUrl";
		 _htmlTitle='title';
		browse('uupload','imgSrc',100,150);

		$('.doubledate').kuiDate({
			className : 'doubledate',
			isDisabled : "0" // isDisabled为可选参数，“0”表示今日之前不可选，“1”标志今日之前可选
		});
		initImage()

	});
	$(function() {
		$("#shopIsChoosed").click(function() {
			if ($("#shopIsChoosed").is(":checked")) {
				$("#shopName").attr("disabled", false);
				$("#research").attr("disabled", false);

			} else {
				$("#shopName").attr("disabled", true);

			}
		});
	})
	function downRescouse() {
		var mp = $("#mp").val().replace(/\s/gi, '');
		var name = $("#name").val().replace(/\s/gi, '');
		var type = $("#type").val();
		var dtBegin = $("#dtBegin").val();
		var dtEnd = $("#dtEnd").val();
		var shopId = "";
		if ($("#shopIsChoosed").is(":checked")) {
			shopId = $("#shopName").val();
			if (shopId != "" && shopId != null) {

			} else {
				shopId = "";
			}
		}

		var params = {
			'mp' : mp,
			'name' : name,
			'type' : type,
			'dtBegin' : dtBegin,
			'dtEnd' : dtEnd,
			'shopId' : shopId
		}
		window.location.href = "../apply/export/csv?" + $.param(params);
	}


	function popPoint(id) {
		art.dialog({
			fixed : true,
			lock : true,
			content : "确认删除该条数据？",
			icon : 'question',
			ok : function() {
				deleteInfo(id)
			},
			cancel : true
		});
	}
	//查询
	function searchApply() {
		getTryDriverList(1);
	}
	function getTryDriverList(index) {
		if (IsEmpty(index)) {
			index = 1
		}

		var mp = $("#mp").val().replace(/\s/gi, '');
		var name = $("#name").val().replace(/\s/gi, '');
		var type = $("#type").val();
		var dtBegin = $("#dtBegin").val();
		var dtEnd = $("#dtEnd").val();
		var participation1=$("#participation1").val();
		var shopId = "";
		if ($("#shopIsChoosed").is(":checked")) {
			shopId = $("#shopName").val();
			if (shopId != "" && shopId != null) {

			} else {
				shopId = "";
			}
		}
		var params = {
			'mp' : mp,
			'name' : name,
			'type' : type,
			'dtBegin' : dtBegin,
			'dtEnd' : dtEnd,
			'shopId' : shopId,
			'participation':participation1
		}
		var dt = _findInfo("../apply/find/applyList/" + (index - 1) + "/10",
				params);
		if (IsNotEmpty(dt) && dt.state == 0) {
			$("#memberList tbody").empty()

			for ( var i = 0; i < dt.result.data.length; i++) {
				var htm = "<tr>"
					htm += "<td>" + _getStringOfJson(i, dt, "type") + "</td>"
					htm += "<td> <img src='" + _getStringOfJson(i, dt, "imageUrl")
							+ "' onclick=\"openImage(\'"
							+ _getStringOfJson(i, dt, "imageUrl") + "\')\" ></td>"
					htm += "<td>" + _getStringOfJson(i, dt, "name") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "mp") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "age") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "address") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "Nation") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "staName") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "height") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "weight") + "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "createdTime")
							+ "</td>"
					var pe=0;
					if( _getStringOfJson(i, dt, "participation")=='1'){
						pe= '参于'
					} else{
						pe= '未参与'
						}
					htm += "<td>" +pe+ "</td>"
					htm += "<td>" + _getStringOfJson(i, dt, "votenum") + "</td>"
					var id = _getIntOfJson(i, dt, "id")
					htm += "<td> <input type='button' class='common_btn' value='设置' class='btn' onclick='setting("
							+ id + ")'>&nbsp;<input class=\"del\" type=\"button\" onclick=\"delApply("+id+")\" value=\"删除\"> </td>"
					htm += "</tr>"
					$("#memberList tbody").append(htm)
				}
				/* 		_loadInfo(dt, "memberList", param)
				 */
				$("#memberList tbody tr").each(function() {

				})
				_loadPage("pager", index, 10, dt, getTryDriverList, "NoResult");
				$("#sup").html("共" + dt.result.len + "条");
		}
	}

	//改变女主播
	function setting(id) {
		resForm();
		var url = " ../apply/find/applyById";
		$("#upid").val(id);
		$("#doflag").val(2)
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				var rst = JSON.parse(g);
				console.log(rst);
				$("#imageUrl").val(_getStringOfJson(0, rst, 'imageUrl'));
				var utype=_getStringOfJson(0, rst, 'type');
				if(utype=='高校'){
					utype=0;
				}else if(utype=='大众'){
					utype=1;
				}
				$("#utype").val(utype);
				$("#imgSrc img").attr("src",_getStringOfJson(0, rst, "imageUrl"))
				$("#indexUrl").val(_getStringOfJson(0, rst, 'imagetext'));
				$("#participation").val(_getStringOfJson(0, rst, 'participation'));
				$("#aName").val(_getStringOfJson(0, rst, 'name'));
				$("#amarry").val(_getStringOfJson(0, rst, 'marry'));
				$("#aAge").val(_getStringOfJson(0, rst, 'age'));
				$("#aPhone").val(_getStringOfJson(0, rst, 'mp'));
				$("#aNation").val(_getStringOfJson(0, rst, 'Nation'));
				$("#height").val(_getStringOfJson(0, rst, 'height'));
				$("#weight").val(_getStringOfJson(0, rst, 'weight'));
				$("#address").val(_getStringOfJson(0, rst, 'address'));
				$("#utype").val(utype);
				
					
			});
			
			$("#yinying1,#window_change").show();
			addMargin($("#window_change"));

		}
	}
	
	function save(){
		var doflag= $("#doflag").val()
		if(doflag==1){
			insertApply()
		}else{
			updateApply()
			}
	}
//更新
	function updateApply() {
		var upid = $("#upid").val();
		var uimagetext=$("#indexUrl").val();
		var uparticipation=$("#participation").val();		
		var name = $("#aName").val();
		var phone = $("#aPhone").val();
		var address = $("#address").val();
		var age = $("#aAge").val();
		var height = $("#height").val();
		var weight = $("#weight").val();
		var utype = $("#utype").val();
		var amarry = $("#amarry").val();
		var aNation = $("#aNation").val();
		var heads = new Array("name", "phone","imagetext","participation","type","age","address","mp","Nation","marry","height","weight","id");
		var datas = new Array(name, phone,uimagetext,uparticipation,utype,age,address,phone,aNation,amarry,height,weight,upid);
		var parser = new Object();
		//alert("图片介绍=="+uimagetext+"==是否参与"+uparticipation+"==赛区"+utype+"==更新路径"+imageurl)
		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "edit", parser);
			jsonParserStr = JSON.stringify(parser);
		}
		var url = " ../apply/up/updateApplyId";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			if(dt.result>0){
				 var n = upload($("#upid").val());
				$("#window_change").hide();
				searchApply();
				if(n==0){
					
				art.dialog({fixed:true, lock: true,content:'修改成功',icon:'succeed',ok:true});
				}else{
					art.dialog({fixed:true, lock: true,content:'图片出错，请在修改也重新上传',icon:'error',ok:true});
				}
				$("#yinying1").hide();
			}else{
				art.dialog({fixed:true, lock: true,content:'修改失败',icon:'error',ok:true});
			}
			console.log(data);
			//saveOwnShopIds();
			
		});

	}
	 function upload(id){
		 var n =0;
		 var fil = $("#uupload").val();
		 if(IsEmpty(fil)){
			 return n = 0;
		 }
		 
		$.ajaxFileUpload({
				url :"../apply/upload/image/"+id, 
				secureuri : false,
				fileElementId : 'uupload',
				dataType : 'json',
				success : function(data){
					if($("#uupload").val()==''){
					}else{
					//alert("上传文件不为空")
					
					if(IsEmpty(data)){
/* 						art.dialog({fixed:false, lock: true,content:"上传图片出错",icon:'error',ok:true});
 */					
						n = 1;
 						return false;
						}
						if(data.state==0){
							
/* 							art.dialog({fixed:false, lock: true,content:"操作成功",icon:'succeed',ok:true});
 */							/*  $("#window_change").hide();
								$("#yinying1").hide();
								searchApply(); */
								browse('uupload','imgSrc',100,150);
								searchApply()
							return false;

						}else if(data.state==1){
/* 							art.dialog({fixed:false, lock: true,content:"保存图片出错,请重新上传图片",icon:'error',ok:true});	
 * 							n-=
 */
 		n=1;				
 			return false;
						}
					}
						
				},
				error : function(data) {
					art.dialog({fixed:true, lock: true,content:'上传图片失败',icon:'error',ok:true});	
					n=1;				
		 			return false;
		 			}
			});
		return n;
		}
	 
	
	
	//删除
	function delApply(id){
		var url = " ../apply/de/deleteById";
		//$("#upid").val(id);
		if (id > 0) {
			$.get(url, {
				"id" : id
			}, function(g) {
				console.log(g);
				var rst = JSON.parse(g);
				if(rst.state==0){
					searchApply();
					art.dialog({fixed:true, lock: true,content:'删除成功',icon:'success',ok:true});
				}
				console.log(rst);
				//$("#Name").val(_getStringOfJson(0, rst, 'name'))
			});
		}
	}
	function showInsert(){
		$("#window_add").show();
		addMargin($("#window_add"));
	}
	aNation
	function resForm(){
		$("#aName").val("");
		$("#aAge").val("");
		$("#aPhone").val("");
		$("#address").val("");
		$("#imageUrl").val("");
		$("#imgSrc").val("");
		$("#indexUrl").val("");
		$("#uupload").val("");
		$("#aNation").val("");
		$("#height").val("");
		$("#weight").val("");
	}
	
	
	function toAdd(){
		resForm();
		$("#doflag").val(1)
		$("#window_change,#yinying1").show();
		addMargin($("#window_change"));
	}
	
	function insertApply(){
		var uimagetext=$("#indexUrl").val();
		var utype=$("#utype").val();
		var uparticipation=$("#participation").val();		
		var name = $("#aName").val();
		var phone = $("#aPhone").val();
		var address = $("#address").val();
		var age = $("#aAge").val();
		var height = $("#height").val();
		var weight = $("#weight").val();
		var atype = $("#atype").val();
		var amarry = $("#amarry").val();
		var aNation = $("#aNation").val();
		var heads = new Array("name", "phone","imagetext","participation","type","age","address","mp","votenum","Nation","marry","height","weight");
		var datas = new Array(name, phone,uimagetext,uparticipation,utype,age,address,phone,0,aNation,amarry,height,weight);
		var parser = new Object();

		var jsonParserStr = null;//定义空头字符串
		if (IsNotEmpty(datas)) {
			addToParser(heads, datas, "add", parser);
			jsonParserStr = JSON.stringify(parser);
		}
		 var fil = $("#uupload").val();

		 if(IsEmpty(fil)){
			 alertErrorMessage("请选择照片");
			 return false
		 }
		
		$("#close_this").attr("disabled", true);
		var url = " ../apply/in/insertApply";
		$.post(url, {
			"data" : jsonParserStr
		}, function(data) {
			$("#close_this").attr("disabled", false);
			var dt = JSON.parse(data);
			//alert(dt.result)
			if(dt.state==0){
				var id = getHeadIndexValue(0, dt, "id");
				 $("#window_change").hide();
				$("#yinying1").hide();
				var rnresult = upload(id);
				searchApply();
				if(rnresult==0){
				art.dialog({fixed:true, lock: true,content:'添加成功',icon:'success',ok:true});
				}else{
					art.dialog({fixed:true, lock: true,content:'图片出错，请在修改也重新上传',icon:'error',ok:true});
				}
			}else{
				art.dialog({fixed:true, lock: true,content:'添加失败',icon:'error',ok:true});
			}
			//saveOwnShopIds();
		});

	}
	/* function openImage(id){
		window.location.href=id;
		
	} */
	function initImage() {
		Shadowbox.init();
		window.openImage = function(url) {
			Shadowbox.open({
				content : url,
				player : 'img'
			});
		};
	}
	
	/* function getHtmlUrl(html) {
		var url = '';
		$.ajax({
			type : "post",
			async : false,
			datatype : "JSON",
			url : "../htmlUtils/htmlFileGender",
			data : {
				'html' : html
			},
			success : function(rst) {
				if ( typeof rst === "string") {
					rst = JSON.parse(rst);
				}
				var response = new qmsk.Response(rst);
				url = response.getValue("url");
			}
		});
		return url;
	}

	function generateHtmlUrl() {
		var html = editorHtml;
		var url = '';
		if (qmsk.isNotEmpty(html)) {
			url = getHtmlUrl(html);
		}
		alert(url);
	}
 */
	
</script>
</head>

<body>
<div id="yinying1"></div>

	<div id="window_change" class="member_search hideDiv"
		style="width: 520px;">
		<div class="closeTop">
			<span class="closeThe" onclick="closeParent($(this))"><img
				src="../images/close.png"></span>
		</div>
		 <input type="hidden" id="upid" />
		<input type="hidden" id="doflag">
		 <input type="hidden"
			id="shopflag"> <input type="hidden" id="defaultCflag">
			<p>
			<label><span> 赛区：</span>
			 	<select id="utype" >
						<option value="0">高校</option>
						<option value="1">大众</option>
				 </select>
			</label>
			<label><span>姓名：</span> <input type="text" id="aName"></label>
			</p>	
			<p>
			<label><span> 婚姻状况：</span>
			 	<select id="amarry" >
						<option value="0">未婚</option>
						<option value="1">已婚</option>
				 </select>
			</label>
			<label><span>年龄：</span> <input type="text" id="aAge"></label>
				<!-- <br> <span id="NameTip" style="display:none;"></span> --> 
		</p>
		<p>
			<label><span>联系方式：</span> <input type="text" id="aPhone">
				<!-- <br> <span id="NameTip" style="display:none;"></span> --> </label>
				<label><span>民族：</span> <input type="text" id="aNation">
				<!-- <br> <span id="NameTip" style="display:none;"></span> --> </label>
		</p>
		<p>
			<label><span>身高：</span> <input type="text" id="height">
				<!-- <br> <span id="NameTip" style="display:none;"></span> --> </label>
				<label><span>体重：</span> <input type="text" id="weight">
				<!-- <br> <span id="NameTip" style="display:none;"></span> --> </label>
		</p>
		<p>
			<label><span>地址：</span> <input type="text"  style="width: 250px;"id="address">
				 </label>
		</p>		
			<p><label><span> 图片路径：</span>
			<input id="imageUrl" class="isDisabled" type="text" readonly="readonly" >
			<input class="btn" type="button" value="..." >
			<input id="uupload" class="file isDisabled" type="file" name="uupload">
			</label>
			<label><span  id="imgSrc"  style="position: absolute;top:-70px;left:400px"><img src="../images/img_activities1.jpg"></span></label>
						</p>
			<p><label><span>图文介绍： </span>
    <input type = "text" id="indexUrl" style="width: 250px;" >
    <input type="button" class="btn" id="editIndex_btn" value="管理首页" >
      </label>
    </p>
			<!-- <p>
			<label><span> 图文介绍：</span>
			 	<textarea id="uimagetext" rows="3" cols="10"></textarea>
			</label>
			</p> -->
			<p>
			<label><span> 参与投票：</span>
			 	<select id="participation" >
						<option value="0">否</option>
						<option value="1">是</option>
				 </select>
			</label>
			</p>
		<input type="hidden" id="updateId"> <input type="hidden" id="upid" />
		
		<div class="submit_btn">
			<input type="button" value="保存信息" class="common_btn" id="close_this"
				onclick="save()">
		</div>
	</div>
	
	<div class="container" id="container">
		<div class="container_R fr">
			<div class="place">报名</div>
			<div class="member_search">

				<p>

					<span> 赛区：</span> <select id="type"" ><option value="">所有</option>
						<option value="0">高校</option>
						<option value="1">大众</option>
					</select>

					<!-- <span> <input type="checkbox" id="shopIsChoosed" style="width:auto;height:auto;border:none;">店面：</span>
        <select id="shopName" onclick="openShopListPanel(this)" disabled="disabled">
        </select> -->
					<span>起始日期：</span> <input type="text" readonly
						class="doubledate ipticon" id="dtBegin" /> <span>截止时间：</span> <input
						type="text" readonly class="doubledate ipticon" id="dtEnd" />
				</p>
				<p>
					<span>姓名：</span> <input type="text" id="name" class="absoluteTxt">
					<span>手机：</span> <input type="text" id="mp" class="absoluteTxt">
					<span>参与投票：</span><select id="participation1"" ><option value="">所有</option>
						<option value="0">未参于</option>
						<option value="1">参于</option>
					</select> 
				</p>
					<input type="button" style="float: right;" value="查询" class="btn" onclick="searchApply()">
				
			</div>

			<table width="100%" class="member_list" cellpadding="0" cellspacing="1" border="0" id="memberList">
				<caption>
					<strong>报名列表 <span id="sup">共0条</span>
					</strong> 
					  <a href="javascript:void(0)" onclick="downRescouse();">导出数据</a>
					 					<input type="button" value="添加" class="common_btn addList" onclick="toAdd()">
				</caption>
				<thead>
					<tr>
						<tr>
						<th width="50">赛区</th>
						<th width="30">照片</th>
						<th width="50">姓名</th>
						<th width="50">手机</th>
						<th width="50">年龄</th>
						<th width="50">地址</th>
						<th width="50">民族</th>
						<th width="50">婚姻状况</th>
						<th width="50">身高(cm)</th>
						<th width="50">体重(kg)</th>
						<th width="60">报名时间</th>
						<th width="60">参与投票否</th>
						<th width="60">投票数</th>
						<th width="60">操作</th>
					</tr>
					</tr>
				</thead>
				<tbody>

				</tbody>
			</table>
			<div id="NoResult" class="Nothing"
				style="text-align: center; display: none;">无符合条件的数据！</div>
			<div id="pager" style="float: right;"></div>
		</div>
		<div class="fc"></div>
	</div>
	<!-- InstanceEndEditable -->
	<script type="text/javascript" src="../js/header.js"></script>
	<script type="text/javascript" src="../js/left.js"></script>
	<script type="text/javascript" src="../js/footer.js"></script>
	<script type="text/javascript" src="../js/ajaxfileupload.js"></script> 
	<script type="text/javascript" src="../js/ImageBrowsing.js"></script> 
	<script charset="utf-8" src="../js/kindeditor.js"></script>
	<script type="text/javascript" src="../js/editor2.js"></script>
	
	<script type="text/javascript">
		clearThis("absoluteTxt");
		showTab(1, 1);
	</script>
</body>
<!-- InstanceEnd -->
</html>
